Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept LSP server #21

Merged
merged 10 commits into from
Apr 4, 2021
Merged

Proof of concept LSP server #21

merged 10 commits into from
Apr 4, 2021

Conversation

mickael-menu
Copy link
Member

@mickael-menu mickael-menu commented Apr 2, 2021

Integrate a Language Server in zk to be used with LSP editors (i.e. neovim).

Features

  • Auto-complete tags with # and : trigger characters.
  • Auto-complete Markdown links with [ and WikiLinks with [[.
  • Open a note from a link (Document links when supported or Go to definition otherwise)
    • Only inline links are supported at the moment, not reference links.
  • Hover to preview the note content of a link.

Pre-release builds

Installation

With coc.nvim, run :CocConfig and add the following to your coc-settings.json:

{
  // Important, otherwise link completion containing spaces and other special characters won't work.
  "suggest.invalidInsertCharacters": [],

  "languageserver": {
    "zk": {
      "command": "zk",
      "args": ["lsp", "--log", "/tmp/zk-lsp.log"],
      "trace.server": "verbose",
      "filetypes": ["vimwiki", "markdown"]
    },
  }
}

While running, you can check the content of /tmp/zk-lsp.log to see the JSON-RPC exchange.

@mickael-menu
Copy link
Member Author

@megalithic I have an issue following links with coc.nvim, I described it here neoclide/coc.nvim#3010. Would you mind checking if you experience the same thing on your environment? Here's a macOS build with the LSP features enabled

@megalithic
Copy link

Extremely excited about this! I use the built in neovim lsp client, so i'll
be checking it with that. Either way, I'll let you know! Thanks again Mickael
and thanks for your support on zk.nvim.

@mickael-menu
Copy link
Member Author

Okay let me know how it goes with the builtin one too. And if you have installation instructions for it I could add them to the doc as well 👍

@megalithic
Copy link

megalithic commented Apr 3, 2021

@mickael-menu -> here's the instructions for nvim-lspconfig setup:

local lspconfig = require('lspconfig')
local configs = require('lspconfig/configs')

configs.zk = {
  default_config = {
    cmd = {'zk', 'lsp', '--log', '/tmp/zk-lsp.log'},
    filetypes = {'markdown'},
    root_dir = function()
      return vim.loop.cwd()
    end,
    settings = {}
  };
}

lspconfig.zk.setup({ on_attach = function(client, buffer) 
  -- some custom on_attach function for doing keybindings and other things..
  -- see: https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
end })

@megalithic
Copy link

@mickael-menu it's looking like we're stuck without certain lsp implementations
in the built-in neovim lsp client; for now. completion works though! that's
exciting! thanks so much for your efforts on this!

@mickael-menu
Copy link
Member Author

Great news, the maintainer of coc.nvim fixed the bug really quickly and following links works properly with the latest version now 🎉

Thanks a lot for the nvim-lspconfig 👍 That's a shame documentLink is not supported, but maybe we can have a workaround by implementing either the "go to definition" handler or a custom "code action". I'll try to implement this.

I see that the built-in LSP nvim API offers some additional features for extensions too, that might be useful for more advanced use cases.

(On an unrelated note, you got me into dotfiles! I just got a new MacBook M1 and I'm taking this opportunity to streamline my startup scripts and share my config files with stow)

@mickael-menu
Copy link
Member Author

@megalithic Here's a new build with Go to definition to follow a link. You should be able to map it with:

nnoremap <silent> <CR> <cmd>lua vim.lsp.buf.definition()<CR>

@mickael-menu
Copy link
Member Author

Here's a screenshot of the Hover feature to preview a note, triggered manually with this coc.nvim mapping:

nnoremap <silent> K :call CocActionAsync('doHover')<CR>

Screenshot 2021-04-03 at 16 21 09

@mhanberg
Copy link
Contributor

mhanberg commented Apr 3, 2021

This looks very promising!

@mickael-menu mickael-menu force-pushed the feature/language-server branch from 479ddbc to ba909db Compare April 4, 2021 12:28
@mickael-menu mickael-menu marked this pull request as ready for review April 4, 2021 13:09
@mickael-menu
Copy link
Member Author

mickael-menu commented Apr 4, 2021

I think the feature set is good enough for basic usage. I'll focus on some architectural changes before tackling the other LSP features mentioned in #22

Here are some pre-release builds:

(UPDATE: fixed the go to definition with neovim 0.5)

@mickael-menu mickael-menu merged commit ba41fe5 into main Apr 4, 2021
@mickael-menu mickael-menu deleted the feature/language-server branch April 4, 2021 13:31
@pinpox pinpox mentioned this pull request Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants